# 20/100 矩阵-旋转图像
# leetcode第48题: https://leetcode.cn/problems/rotate-image/?envType=study-plan-v2&envId=top-100-liked
# Date: 2024/12/17
from leetcode import test


def rotate(matrix: list[list[int]]):
    n = len(matrix)
    for i in range(n):
        for j in range(i + 1, n):
            matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]

    for i in range(n):
        for j in range(n):
            if j < n // 2:
                matrix[i][j], matrix[i][n - j - 1] = matrix[i][n - j - 1], matrix[i][j]

    return matrix


if __name__ == '__main__':
    inp = [{"matrix": [[1, 2, 3],
                       [4, 5, 6],
                       [7, 8, 9]]},
           {"matrix": [[5, 1, 9, 11],
                       [2, 4, 8, 10],
                       [13, 3, 6, 7],
                       [15, 14, 12, 16]]}, ]
    out = [[[7, 4, 1],
            [8, 5, 2],
            [9, 6, 3]],

           [[15, 13, 2, 5],
            [14, 3, 4, 1],
            [12, 6, 8, 9],
            [16, 7, 10, 11]]
           ]

    print(rotate([[1, 2, 3],
                  [4, 5, 6],
                  [7, 8, 9]]))
    test.test_function(rotate, inp, out)
